package cn.tedu.mall.seckill.timer.QuertzConfig;

import cn.tedu.mall.seckill.timer.job.SeckillInitJob;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author BJ
 * @date 2022/11/8 20:36
 */
@Slf4j
@Configuration
public class SeckillConfig {

    @Bean
    public JobDetail initJobDetail(){
        // 通过反射得到job
        return JobBuilder.newJob(SeckillInitJob.class)
                .withIdentity("jobSeckill")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger initTrigger(){
        return TriggerBuilder.newTrigger()
                .forJob(initJobDetail())
                .withIdentity("initTrigger")
                .withSchedule(CronScheduleBuilder.cronSchedule("0 55 11,13,15,17 * * ?")) //秒杀前五分钟进行任务
                .build();
    }
}
